<form class="layui-form layui-box" style='padding:25px 30px 20px 0' action="{:url()}"  method="post">
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" name="title" value='${obj.title!""}' required="required" lay-verify="required" title="请输入标题" placeholder="请输入标题" class="layui-input">
        </div>
         <label class="layui-input-block layui-word-aux">(例如影片名称为《平博士密码》，则视频名称为《平博士密码第一集》、《平博士密码第二集》..)</label>
    </div>
	<div class="layui-form-item">
        <label class="layui-form-label">视频地址</label>
        <div class="layui-input-block">
            <input type="text" name="url" value='${obj.url!""}' required="required" lay-verify="url" title="请输入视频地址" placeholder="请输入视频地址" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">视频长度（秒）</label>
        <div class="layui-input-inline">
            <input type="text" name="length" value='${obj.length?c}' required="required" lay-verify="number" title="请输入视频长度" placeholder="请输入视频长度" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图片</label>
        <div class="layui-input-inline">
        	<img data-tips-image="" style="height:auto;max-height:60px;min-width:60px" src="${obj.img!''}" id="img_src"/>
            <input type="hidden" id="img" name="img" value="${obj.img!''}" required="required" lay-verify="required" class="layui-input">
            <input type="file" name="file" class="layui-upload-file" id="img_file" >
        </div>
        <label class="layui-input-inline layui-word-aux">(尺寸：360：220(1.64接近16:10))</label>
    </div>
    
    <div class="hr-line-dashed"></div>
    <div class="layui-form-item text-center">
        <input type='hidden' value='${obj.id?c}' name='id'/>
        <input type='hidden' value='${obj.resourceId?c}' name='resourceId'/>
        <button class="layui-btn" type='button' lay-submit lay-filter="*">保存数据</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-close>取消编辑</button>
    </div>

    <script>window.form.render();</script>
</form>
<div class="loading_img"></div>
<script>
layui.use(['form','upload'], function(){
	var form = layui.form();
	
	//监听提交
    form.on('submit(*)', function (data) {
    	console.log(data.field);
    	$.post('resource/saveData', data.field, function (result) { 
    		if(result.code==1){
	        	layer.closeAll();
	            layer.msg(result.msg, {
	                icon: 1,
	                shade: this.shade,
	                scrollbar: false,
	                time: 2000,
	                shadeClose: true
	            });//保存成功提示
	            $.form.reload();//刷新表单
	        }else{
	            layer.msg(result.msg, {
	                icon: 2,
	                shade: this.shade,
	                scrollbar: false,
	                time: 3000,
	                shadeClose: true
	            });
	        }
	        
	        $.form.reload();//刷新表单
		},"json");
        return false;
    });
	
    layui.upload({
	  elem: '#img_file',
	  url: 'file/upload',
	  ext: 'jpg|png|gif',
	  before:function(res){
		  $(".loading_img").show();
	  },
	  success: function(res){
	    if(res.code==0){
	    	var img_str = res.data.path;
	    	$("#img_src").attr("src",img_str);
	    	$("#img").val(img_str);
	    }else{
	    	layer.msg("上传失败", {
                icon: 2,
                shade: this.shade,
                scrollbar: false,
                time: 3000,
                shadeClose: true
            });
	    }
	    $(".loading_img").hide();
	  }
	});
	  
});
</script>